/**************************************************************************************
*
*	Copyright (C) 2010 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	CameraRenderPathSettingsFP
*
*	Description -	Settings and data specific to the view to be used by the 
*					Forward+ render path
*
*	Comments	-	TODO: Make it so that this implementation is derived from 
*						IRenderPathViewSettings interface.
*
*	Modification History:
*			Name			   Date					Description
*			MrCodeSushi	-	07/23/2013		-	File creation
**************************************************************************************/
#ifndef _PSX_FP_VIEW_SETTINGS_H_
#define _PSX_FP_VIEW_SETTINGS_H_

#include "PulseSTD.h"

namespace Pulse
{
	class CameraRenderPathSettingsFP
	{
	public:

		void ReleaseBuffers( void );

		// NOTE: Release and recreate new texture buffers 
		//	to the view's updated size
		EErrorCode::Type UpdateBufferSizes( void );

		Texture2D * GetCompositeTexture( void );

		virtual void OnRender( RenderView *pView );

	public:

		StructuredBuffer * GetLightsBuffer( void ) { return m_pBufferLights; }

		Buffer * GetLightIndicesBuffer( void ) { return m_pBufferLightIndices; }

	private:

		friend RenderPathForwardPlus;

		CameraRenderPathSettingsFP( ComponentCamera *pCamera );

		virtual ~CameraRenderPathSettingsFP( void );

		EErrorCode::Type Initialize( void );

		void Cleanup( void );

	private:

		// Utility Methods
		//////////////////

		void BindBuffers( Texture2D *pDepthBuffer, StructuredBuffer *pLightsBuffer, Buffer *pLightIndices, Texture2D *pCompositeBuffer );

		const UINT ComputeNumThreadGroups( const UINT threadGroupSize, const UINT numElements ) const;

	private:

		void OnPreRenderViewExecute( RenderView *pView );

	private:

		static const UINT m_tileSize;
		static const UINT m_threadGroupSize;
		static const UINT m_threadGroupMaxLights;

		ComponentCamera *m_pCameraOwner;

		StructuredBuffer		*m_pBufferLights;		// Light structure to be stored here
		Buffer					*m_pBufferLightIndices;	// RW - indices storing lights in tiles
		ParameterBinderScalar	*m_pNumLights2;
		ParameterBinderScalar	*m_pNumLights3;

		// OLD SETTINGS DATA
		/////////////////////////////////////////////////

		// Buffers
		Texture2D	*m_pDepthBuffer;
		Texture2D	*m_pCompositeBuffer; 

		// States
		DepthStencilState *m_pDSState2n3;

		// Render entries
		RenderEntryViewport				*m_pREViewport; // TODO: Move this in camera

		// Z-prepass
		RenderEntryRenderTarget			*m_pRERenderTarget1;		
		RenderEntryDepthStencilState	*m_pREDepthStencil1;
		RenderEntryClearPipeline		*m_pREClearPipeline1;

		// Lighting pass
		RenderEntryBindParameters		*m_pREBindParams2; // Currently not being used
		RenderEntryDispatchCompute		*m_pREDispatchCompute;
		RenderEntryClearPipeline		*m_pREClearPipeline2;

		// Composite pass
		RenderEntryRenderTarget			*m_pRERenderTarget3;		
		RenderEntryDepthStencilState	*m_pREDepthStencil3;
		RenderEntryBindParameters		*m_pREBindParams3;
		RenderEntryClearPipeline		*m_pREClearPipeline3;

		RenderEntryPresent				*m_pREPresent;

	};
}

#endif /* _PSX_FP_VIEW_SETTINGS_H_ */